package com.gree.flowable.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @author ：180849
 * @date ：Created in 2021/4/1 17:25
 * @description：实例化表单数据DAO
 * @modified By：
 * @version: 1.0
 */
@Repository
public interface FormDataMapper extends BaseMapper {
    /**
     * 删除表单数据
     * @param businessKey   流程实例(主键)
     * @param formId        表单名(数据表名)
     * @return      删除条数
     */
    @Delete("delete from ${formId} where businessKey = #{businessKey}")
    @ResultType(Integer.class)
    Integer deleteFormData(@Param("businessKey") String businessKey, @Param("formId") String formId);

    /**
     * 查询数据是否插入成功
     * @param businessKey   流程实例(主键)
     * @param formId        表单名(数据表名)
     * @return
     */
    @Select("select count(1) from ${formId} where business_key = #{businessKey}")
    @ResultType(Integer.class)
    Integer queryFormData(@Param("businessKey") String businessKey, @Param("formId") String formId);

    @Select("select * from ${formId} where business_key = #{businessKey}")
    Map<String,Object> quryData(@Param("businessKey") String businessKey, @Param("formId") String formId);

    /**
     * 更新数据
     * @param businessKey 单号
     * @param formId       表单id
     * @param data          表单数据
     * @return
     */
    Integer updateFormData(@Param("businessKey") String businessKey, @Param("formId") String formId, @Param("data") Map<String, Object> data);

    /**
     * 添加数据
     * @param businessKey 单号
     * @param formId       表单id
     * @param data          表单数据
     * @return
     */
    Integer addFormData(@Param("businessKey") String businessKey, @Param("formId") String formId, @Param("data") Map<String, Object> data);
}
